package com.lanju.app.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.lanju.app.message.bean.B106Request;
import com.lanju.app.message.bean.B106Response;
import com.lanju.app.message.bean.B106Response.OrderShopBean;
import com.lanju.app.util.AppUtil;
import com.lanju.entity.User;

/**
 * 获取某日订单列表（按店铺分类）
 * @author fly
 *
 */
@Service("B106Service")
public class B106Service extends BaseService<B106Request,B106Response>{

	@Override
	public B106Response doService(B106Request request, User u) throws Exception {
		B106Response res = new B106Response();		
		if(StringUtils.isBlank(request.getDate())){
			res.setMessage("订单日期参数错误！");
			return res;
		}
		
		String sql = " SELECT o.id AS orderId, shop_id AS shopId, shop_name AS shopName, o.amount, o.address, o.tel, CONCAT(\"http://lanju.oss-cn-shenzhen.aliyuncs.com/\",s.path) AS path FROM `order` o LEFT JOIN shop s ON o.shop_id=s.id WHERE busi_id=? AND date(o.created_time)=? ";
		ArrayList<String> param = new ArrayList<>();
		param.add(request.getToken());		
		param.add(request.getDate());		
		List<OrderShopBean> beans = dao.list(sql.toString(), OrderShopBean.class,  param.toArray());
		for(OrderShopBean bean : beans){
			bean.setPathSl(bean.getPath()+AppUtil.oss_bucket_thumb150x150);
		}
		res.setBeans(beans);
		res.setSuccess(true);
		return res;
	}
}
